/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package persistence;

import java.util.ArrayList;
import java.util.List;

/**
 * This is the main class that contains the main method used
 * to test the persistence entities that we created. It is only
 * used for test purposes in order to avoid the run of the entire
 * helpdesk project.
 * 
 * This class will print the list of tickets in the console.
 * 
 * @author Amigos do Noddy
 *
 */
public class Main {
    //EntityManagerFactory emf;
    //EntityManager em;
    
    public void init() {
        //emf = Persistence.createEntityManagerFactory("persistencePU");
        //em = emf.createEntityManager();
    }
    
    @SuppressWarnings("unused")
	private void shutdown() {
        //em.close();
        //emf.close();
    }
    
    private void search() {
        
        //MyEntityManagerFactory emf = MyEntityManagerFactory.getInstance();
        
        //EntityManager em = emf.createEntityManager();
        
        //EntityTransaction tx = em.getTransaction();
        //tx.begin();
        System.out.println("\nsearching for tickets");
        
        //Query query = em.createQuery("select t from Utilizador t");
     
        List<Utilizador> results = (List<Utilizador>)Command.select("select t from Utilizador t", new ArrayList());
        
        //List<Utilizador> results = (List<Utilizador>)query.getResultList();
      
        for(Utilizador t : results) {
                //System.out.println("got a ticket: " + t.getTicketCollection());
                List<Ticket> l = (List<Ticket>) t.getTicketCollection();
                System.out.println("Utilizador: " + t.getName());
                for(int i = 0; i< l.size(); i++)
                    System.out.println("Ticket: " + l.get(i).getTitle());
                
        }
        System.out.println("done searching for tickets\n");
        //tx.commit();
        
        //em.close();
        //emf.close();
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        // TODO code application logic here
        Main main = new Main();
        //main.init();
        try {
            main.search();
        } catch (RuntimeException ex) {
            ex.printStackTrace();
        } finally {
            //main.shutdown();
        }
    }

}
